D 		 [0-9]
L 		 [a-zA-Z_]
%{
extern "C" {
int yywrap(void);
int yylex(void);
}

#include <iostream>
#include <string>
#define YYSTYPE node*

#include "head.h"
#include "frame.tab.h"
int yylex();

extern YYSTYPE yylval;


void count();
%}
%%
"#"[^\n]*$ 	 { printf(" COMMENT ");}
"and" 		 { count(); node *nt = new terminal_node("AND");yylval = nt; return(AND); }
"bool" 		 { count(); node *nt = new terminal_node("BOOL");yylval = nt; return(BOOL); }
"def" 		 { count(); node *nt = new terminal_node("DEF");yylval = nt; return(DEF); }
"else" 		 { count(); node *nt = new terminal_node("ELSE"); yylval = nt;return(ELSE); }
"float" 	 { count(); node *nt = new terminal_node("FLOAT"); yylval = nt;return(FLOAT); }
"for" 		 { count(); node *nt = new terminal_node("FOR"); yylval = nt; return(FOR); }
"if" 		 { count(); node *nt = new terminal_node("IF"); yylval = nt; return(IF); }
"int"		 { count(); node *nt = new terminal_node("INT"); yylval = nt;return(INT); }
"or" 		 { count(); node *nt = new terminal_node("OR"); yylval = nt;return(OR); }
"pic" 		 { count(); node *nt = new terminal_node("PIC"); yylval = nt;return(PIC); }
"pixel" 	 { count(); node *nt = new terminal_node("PIXEL"); yylval = nt;return(PIXEL); }
"return" 	 { count(); node *nt = new terminal_node("RETURN"); yylval = nt;return(RETURN); } 
"to" 		 { count(); node *nt = new terminal_node("TO"); yylval = nt;return(TO); }
"video" 	 { count(); node *nt = new terminal_node("VIDEO"); yylval = nt;return(VIDEO); }
"void" 		 { count(); node *nt = new terminal_node("VOID"); yylval = nt;return(VOID); }
"while"		 { count(); node *nt = new terminal_node("WHILE"); yylval = nt;return(WHILE); }
"true" 		 { count(); node *nt = new terminal_node("TRUE"); yylval = nt;return(TRUE); }
"false" 	 { count(); node *nt = new terminal_node("FALSE"); yylval = nt;return(FALSE); }
"elif" 		 { count(); node *nt = new terminal_node("ELIF"); yylval = nt;return(ELIF); }



{L}({L}|{D})* 	 { count(); node *nt = new terminal_node("ID", yytext); yylval = nt;return(IDENTIFIER); }

{D}+("."{D}+)? 		 { count(); node *nt = new terminal_node("CONSTANT",yytext); yylval = nt;return(CONSTANT); }
\"(\\.|[^\\"])*\" { count(); node *nt = new terminal_node("STRING_LITERAL",yytext); yylval = nt; return(STRING_LITERAL); }


"<-" 	 { count(); node *nt = new terminal_node("INPUT_OP"); yylval = nt;return(INPUT_OP); }

"<=" 		 { count(); node *nt = new terminal_node("LE_OP"); yylval = nt;return(LE_OP); }
">=" 		 { count(); node *nt = new terminal_node("GE_OP"); yylval = nt;return(GE_OP); }
"==" 		 { count(); node *nt = new terminal_node("EQ_OP"); yylval = nt;return(EQ_OP); }
"!=" 		 { count(); node *nt = new terminal_node("NE_OP"); yylval = nt;return(NE_OP); }
";" 		 { count(); return(';'); }

"{" 		 { count(); node *nt = new terminal_node("{"); yylval = nt;return('{'); }
"}" 		 { count(); node *nt = new terminal_node("}"); yylval = nt;return('}'); }
"," 		 { count(); node *nt = new terminal_node(","); yylval = nt;return(','); }
":" 		 { count(); node *nt = new terminal_node(":"); yylval = nt;return(':'); }
"=" 		 { count(); node *nt = new terminal_node("="); yylval = nt;return('='); }
"(" 		 { count(); node *nt = new terminal_node("("); yylval = nt;return('('); }
")" 		 { count(); node *nt = new terminal_node(")"); yylval = nt;return(')'); }
"[" 		 { count(); node *nt = new terminal_node("["); yylval = nt;return('['); }
"]" 		 { count(); node *nt = new terminal_node("]"); yylval = nt;return(']'); }
"." 		 { count(); node *nt = new terminal_node("."); yylval = nt;return('.'); }
"&" 		 { count(); node *nt = new terminal_node("&"); yylval = nt;return('&'); }
"!" 		 { count(); node *nt = new terminal_node("!"); yylval = nt;return('!'); }
"-" 		 { count(); node *nt = new terminal_node("-"); yylval = nt;return('-'); }
"+" 		 { count(); node *nt = new terminal_node("+"); yylval = nt;return('+'); }
"*" 		 { count(); node *nt = new terminal_node("*"); yylval = nt;return('*'); }
"/" 		 { count(); node *nt = new terminal_node("/"); yylval = nt;return('/'); }
"%" 		 { count(); node *nt = new terminal_node("%"); yylval = nt;return('%'); }
"<" 		 { count(); node *nt = new terminal_node("<"); yylval = nt;return('<'); }
">" 		 { count(); node *nt = new terminal_node(">"); yylval = nt;return('>'); }


[ \t\v\n\f] 	 { count(); }
. 		 { /* ignore bad characters */ }
%%
int yywrap(void)
{
 	return 1;
}
int column = 0;

void count()
{
 int i;

 for (i = 0; yytext[i] != '\0'; i++)
 	 if (yytext[i] == '\n')
 		 column = 0;
 	 else if (yytext[i] == '\t')
 		 column += 8 - (column % 8);
 	 else
 		 column++;

 ECHO;
}
